;layui.define(function(e) {
    layui.use(['table','layer','form','laydate','element'], function(){
        var $ = layui.$
            ,layer = layui.layer
            ,form = layui.form
            ,laydate = layui.laydate
            ,element = layui.element
            ,table = layui.table;
        laydate.render({
            elem: '#date1'
        });
        laydate.render({
            elem: '#date2'
        });
        laydate.render({
            elem: '#date3'
        });

       var table1= table.render({
            elem: '#idTest1'
            ,cols: [[ //标题栏
                {field: 'brand', title: '品牌'}
                ,{field: 'carSeries', title: '车系'}
                ,{field: 'carType', title: '车型', minWidth: 120}
                ,{field: 'guidePrice', title: '指导价(元)', sort: true}
                ,{field: 'purchasePrice', title: '采购价(元)', sort: true}
                ,{field: 'closePrice', title: '批售价(元)', sort: true}
                ,{field: 'color', title: '外观/内饰颜色'}
                ,{field: 'VIN', title: '车架号'}
                ,{field: 'warehouseEntryTime', title: '入库时间'}
                ,{field: 'libraryAge', title: '库龄',sort: true}
                ,{field: 'carAge', title: '车龄',sort: true}
                ,{field: 'dealer', title: '经销商'}
                ,{field: 'inventoryStatus', title: '库存状态'}
                ,{field: 'warningStatus', title: '预警状态'}
                ,{field: 'tool',title: '操作',fixed: 'right', minWidth:100, align:'center', toolbar: '#barDemo1'}
            ]]
            ,cellMinWidth: 120
            ,data: [{
                "brand": "库存车辆"
                ,"carSeries": "杜甫"
                ,"carType": "xianxin@layui.com"
                ,"guidePrice": "男"
                ,"purchasePrice": "浙江杭州"
                ,"closePrice": "人生恰似一场修行"
                ,"color": "外观/内饰颜色"
                ,"VIN": "车架号"
                ,"warehouseEntryTime": "车架号"
                ,"libraryAge": "192.168.0.8"
                ,"carAge": "108"
                ,"dealer": "2016-10-14"
                ,"inventoryStatus": "192.168.0.8"
                ,"warningStatus": "192.168.0.8"
            }]
            ,page: true //是否显示分页
        });
        var table2= table.render({
            elem: '#idTest2'
            ,cols: [[ //标题栏
                {field: 'brand', title: '品牌'}
                ,{field: 'carSeries', title: '车系'}
                ,{field: 'carType', title: '车型', minWidth: 120}
                ,{field: 'guidePrice', title: '指导价(元)', sort: true}
                ,{field: 'purchasePrice', title: '采购价(元)', sort: true}
                ,{field: 'closePrice', title: '批售价(元)', sort: true}
                ,{field: 'color', title: '外观/内饰颜色'}
                ,{field: 'VIN', title: '车架号'}
                ,{field: 'warehouseEntryTime', title: '入库时间'}
                ,{field: 'libraryAge', title: '库龄',sort: true}
                ,{field: 'carAge', title: '车龄',sort: true}
                ,{field: 'dealer', title: '经销商'}
                ,{field: 'inventoryStatus', title: '库存状态'}
                ,{field: 'warningStatus', title: '预警状态'}
                ,{field: 'tool',title: '操作',fixed: 'right', minWidth:100, align:'center', toolbar: '#barDemo2'}
            ]]
            ,cellMinWidth: 120
            ,data: [{
                "brand": "库存车辆2"
                ,"carSeries": "杜甫"
                ,"carType": "xianxin@layui.com"
                ,"guidePrice": "男"
                ,"purchasePrice": "浙江杭州"
                ,"closePrice": "人生恰似一场修行"
                ,"color": "外观/内饰颜色"
                ,"VIN": "车架号"
                ,"warehouseEntryTime": "车架号"
                ,"libraryAge": "192.168.0.8"
                ,"carAge": "108"
                ,"dealer": "2016-10-14"
                ,"inventoryStatus": "192.168.0.8"
                ,"warningStatus": "192.168.0.8"
            }]
            ,page: true //是否显示分页
        });
        var table3 = table.render({
            elem: '#idTest3'
            ,cols: [[ //标题栏
                {field: 'brand', title: '品牌'}
                ,{field: 'carSeries', title: '车系'}
                ,{field: 'carType', title: '车型', minWidth: 120}
                ,{field: 'guidePrice', title: '指导价(元)', sort: true}
                ,{field: 'purchasePrice', title: '采购价(元)', sort: true}
                ,{field: 'closePrice', title: '批售价(元)', sort: true}
                ,{field: 'color', title: '外观/内饰颜色'}
                ,{field: 'VIN', title: '车架号'}
                ,{field: 'warehouseEntryTime', title: '入库时间'}
                ,{field: 'libraryAge', title: '库龄',sort: true}
                ,{field: 'carAge', title: '车龄',sort: true}
                ,{field: 'dealer', title: '经销商'}
                ,{field: 'inventoryStatus', title: '库存状态'}
                ,{field: 'warningStatus', title: '预警状态'}
                ,{field: 'tool',title: '操作',fixed: 'right', minWidth:100, align:'center', toolbar: '#barDemo3'}
            ]]
            ,cellMinWidth: 120
            ,data: [{
                "brand": "库存车辆3"
                ,"carSeries": "杜甫"
                ,"carType": "xianxin@layui.com"
                ,"guidePrice": "男"
                ,"purchasePrice": "浙江杭州"
                ,"closePrice": "人生恰似一场修行"
                ,"color": "外观/内饰颜色"
                ,"VIN": "车架号"
                ,"warehouseEntryTime": "车架号"
                ,"libraryAge": "192.168.0.8"
                ,"carAge": "108"
                ,"dealer": "2016-10-14"
                ,"inventoryStatus": "192.168.0.8"
                ,"warningStatus": "192.168.0.8"
            }]
            ,page: true //是否显示分页
        });

        //监听工具条
        table.on('tool(carInquireTable)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                var index = layer.open({
                    type: 2
                    ,id: (new Date()).valueOf()
                    ,title: '详情'
                    ,content: '../car_inventory/inventory.html'
                    ,area: ['500px', '500px']
                    ,btn: ['确定', '取消']
                    ,maxmin: true
                    ,success: function(layero, index){
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
//                        console.log(body.html()) //得到iframe页的body内容
                    }
                    ,yes: function (index,layero) {
                        layer.alert("确定按钮");
                        return false //开启该代码可禁止点击该按钮关闭
                    }
                    ,btn2: function (index,layero) {
                        layer.alert("取消按钮")
                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                });
                layer.full(index);
            }
        });
        form.render();
    });
    //输出模块
    e("inventory", {})
});